layui.use(['table', 'layer'], function () {
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    //表格中的toolbar被点击时事件处理
    table.on('tool(wardTable)',function(obj){
        if(obj.event === "edit"){
            window.location.href="/ward?action=edit&id="+obj.data.id;
        }
        if(obj.event === "del"){
            layer.confirm("你确定要删除该病房吗？", function () {
                $.get("/ward?action=del&id=" + obj.data.id, function () {
                    $("#searchBtn").click();
                    layer.closeAll();
                });
            }, function () {});
        }
    });
    //查询按钮绑定事件
    $("#searchBtn").on("click",function (){
        table.render({
            elem: "#wardTable",
            cols: [[{type: 'numbers', title: '序号',align:'center',width:'10%'},
                {field: 'deptName', title: '科室',width:'20%',align:'center'},
                {field: 'wardno', title: '病房号',width:'20%',align:'center'},
                {field: 'address', title: '地址',width:'30%',align:'center'},
                {title: '操作', toolbar: '#barDemo',width:'20%',align:'center'},
                {field:'id',title:'ID',hide:true}
            ]],
            limit: 5,
            limits: [5, 10, 15, 20, 25, 30],
            layout:['limit', 'prev', 'page', 'next', 'count'],
            url: "/ward",
            where: {action: "list", name: $("#wardno").val()},
            page: true
        });
    }).click();
    $("#addBtn").on("click",function(){
        window.location.href="/ward/add.jsp";
    });
});

